package com.lizi.core.java.lang;

import java.util.Arrays;

public class StringMark {

	public static void main(String[] args) {
		String str = "1asd1111sadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
		System.out.println(str.hashCode());
		
		String a = "1";
		String b = "1";
		System.out.println(a == b);
 
		String bbb = new String("22asdasd2");
		String aaa = "22asdasd2";
		
		System.out.println(aaa == bbb);
		
		String s = new String("1").intern();
	    String s2 = "1";
	    System.out.println(s == s2);
	    String s3 = new String("1") + new String("1");
	    s3.intern();
	    String s4 = "11";
	    String s5 = "1"+"1";
	    System.out.println(s3 == s4);
	    System.out.println(s4 == s5);
	    
	    System.out.println("aa".equals(null));
	}

	/** The value is used for character storage. */
	private final char value[];

	/** Cache the hash code for the string */
	private int hash; // Default to 0

	public StringMark() {
		this.value = "".toCharArray();
	}

	public StringMark(char value[]) {
		this.value = Arrays.copyOf(value, value.length);
	}

	public int hashCode() {
		int h = hash;
		if (h == 0 && value.length > 0) {
			char val[] = value;

			for (int i = 0; i < value.length; i++) {
				h = 31 * h + val[i];
			}
			hash = h;
		}
		return h;
	}

}
